<%-- 
    Document   : Home
    Created on : Apr 21, 2013, 10:59:58 PM
    Author     : Sean
--%>

<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@page import="java.util.ArrayList, business.*, databaseproject.*" contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Shopping Cart</title>
        <link rel="stylesheet" type="text/css" href="site.css">
    </head>
    <body>


        <div id="Main-wrapper">

            <div id="header-wrapper">
                <div id="header">
                    <div class="header-content">
                        IST 411 E-Commerce
                    </div> 
                </div>

                <div id="nav">
                    <ul>
                        <li><a href="index.jsp">Home</a></li>
                        <li><a href="BrowseServlet?catalog_id=1">Browse</a></li>
                        <li><a class="active" href="#">Shopping Cart</a></li>
                        <li><a href="shippingcheckout.jsp">Checkout</a></li>
                    </ul>
                </div>
            </div>

            <div id="Main-content">

                <table class="shop">
                    <tr>
                        <th></th>
                        <th>Name</th>
                        <th>Price</th>
                        <th></th>
                    </tr>
                    <tr>
                        <% 
                       Cart cart = (Cart) session.getAttribute("cart"); 
                       session.setAttribute("cart", cart);
                       ArrayList<LineItem> items = cart.getItems();
                       for (int i=0; i<items.size(); i++)
                       {
                           Products product = items.get(i).getProduct();
                                
                        %>  


                        <td><img src='<% out.println(request.getContextPath() + product.getImage_link()); %>' width="150" height='125' /></td>
                        <td><%= product.getName() %></td>
                        <td>$<%= product.getPrice() %></td>
                        <td><form action="CartServlet" method="post">
                                <input type="hidden" name="productCode" 
                                       value="<%=product.getProduct_id()%>">
                                <input type="hidden" name="quantity" 
                                       value="0">
                                <input type="submit" value="Remove Item">
                            </form></td>
                    </tr>

<% } %>
                    

                </table>


                <div style="text-align: right; margin-right: 40px; margin-top: 10px;">
                    <span style="font-weight: bold; font-size: 1.3em;">SubTotal:</span> <span style="color: #002B6B;">$<%
                    int total = 0;
                       
                       for (int i=0; i<items.size(); i++)
                       {
                           
                           total += Double.valueOf(items.get(i).getProduct().getPrice());  
                    
                       }
                       
                       out.println(String.valueOf(total));
                    %></span>
                    <br/>
                    <br/>
                    <button onclick="window.location.href='BrowseServlet?catalog_id=1'" style="height: 30px;">Continue Shopping</button> &nbsp; &nbsp;<button onclick="window.location.href='shippingcheckout.jsp'" style="height: 30px; background: #FFFF99;">Proceed to Checkout</button>
                </div>
            </div>
            <div id="footer">
                &copy; 2013 | All Rights Reserved
            </div>

        </div>



    </body>
</html>
